package com.example.mymvvmdemo.models.add_article.adapter;

import android.content.Context;

import com.example.mymvvmdemo.base.BaseVBAdapter;
import com.example.mymvvmdemo.databinding.ItemBlogTagBinding;
import com.example.mymvvmdemo.models.add_article.entity.BlogTagEntity;
import com.example.mymvvmdemo.utils.StrUtils;

import java.util.ArrayList;

public class BlogTagAdapter extends BaseVBAdapter<BlogTagEntity.DataDTO, ItemBlogTagBinding> {

    public TagListener listener;

    public void setListener(TagListener listener) {
        this.listener = listener;
    }

    /**
     * @param context
     */
    public BlogTagAdapter(Context context, ArrayList<BlogTagEntity.DataDTO> list) {
        super(context);
        setDataList(list);
    }

    @Override
    protected void updateData(ItemBlogTagBinding bind, BlogTagEntity.DataDTO item, int position) {

        String name = item.getName();
        if (!StrUtils.isEmpty(name)) {
            bind.tvTag.setText(name);
        }

        boolean select = item.isSelect();
        bind.tvTag.setAlpha(select ? 1.0f : 0.5f);

        bind.tvTag.setOnClickListener(view -> {
            if (listener != null) {
                listener.onClickTag(position);
            }
        });

    }


    public interface TagListener {
        void onClickTag(int position);
    }

}
